package com.hermes.comics.data;

import android.content.Context;

import com.hermes.comics.R;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

public abstract class IssueFilter {

  private final int resId;

  public IssueFilter(int resId) {
    this.resId = resId;
  }

  public String title(Context context) {
    return context.getString(resId);
  }

  public abstract List<Issue> issues(Serie serie);

  public static final IssueFilter NONE = new IssueFilter(R.string.issue_filter_all) {
    @Override
    public List<Issue> issues(Serie serie) {
      return serie.issues();
    }
  };

  public static final IssueFilter MISSING = new IssueFilter(R.string.issue_filter_missing) {
    @Override
    public List<Issue> issues(Serie serie) {
      return filterIssue(serie, serie.missing());
    }
  };

  private static List<Issue> filterIssue(Serie serie, Set<Issue> set) {
    List<Issue> result = new ArrayList<Issue>();
    for (Issue issue : serie.issues()) {
      if (set.contains(issue)) {
        result.add(issue);
      }
    }
    return result;
  }
}
